<template>
  <el-container>
    <!--头部-->
    <el-header style="min-height: 190px">
      <v-head></v-head>
    </el-header>
    <el-main>
      <div class="posts_container">
        <el-row>
          <el-col :span="20" :offset="2">
            <div class="outline">
              <div
                class="content"
              >
                <div class="top" style="flow:right">
                    <el-row>
                      <el-col :span="2" :offset="20">
                        <a href="javascript:history.back(-1)"
                    >返回<i class="el-icon-back"></i
                  ></a>
                      </el-col>
                    </el-row>
                </div>
                <div class="title">
                  <h1>{{downloads.title}}</h1>
                  <p>
                    上传日期：{{downloads.createTime}}&emsp;&emsp;&emsp;&emsp;&emsp;<span v-if="downloads.author!=null">作者：{{posts.author}}</span>
                  </p>
                </div>
                <br>
                <p>请下载附件:</p>

                <p>附件【 <a href="javascript:" @click="downloadFile">{{downloads.filename}}</a> 】已下载{{downloads.number}}次</p>
                
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-main>
    <el-footer>
      <v-footer></v-footer>
    </el-footer>
  </el-container>
</template>

<script>
import vHead from "@/views/home/header.vue";
import vFooter from "@/views/home/footer.vue";
import Share from "@/views/posts/share.vue";

import { findById } from "@/api/datum";
export default {
  data() {
    return {
      id:-1,
      downloads:{}
    };
  },
  methods: {
    //下载文件
    downloadFile(){
      window.location.href = "http://localhost:8082/datum/fileDownload?id="+this.downloads.id;
    },
    async getData(){
      const { data: res } = await findById(this.id);
       if (200 == res.code) {
         console.log(res.data);
         this.downloads=res.data
       } else {
         this.$message.error("查找失败！");
       }
    }
  },
  components: {
    vHead,
    vFooter,
    Share
  },
  created(){
    this.id=this.$route.query.id
    this.getData();
    //this.downloads=this.$route.query
  }
};
</script>

<style scoped>
.posts_container .outline {
  border: #0066ff 1px solid;
  padding: 60px 120px;
  min-height: 300px;
}
/* 标题样式 */
.posts_container .outline .title{
  text-align: center;

}
.posts_container .outline .title h1{
  color: #2b2b2b;
    font-size: 22px;
    line-height: 2em;
    text-align: center;
    padding: 10px 0;
    border-bottom: 1px solid #dedede;
    margin-bottom: 0.7em;
}

.posts_container .outline .title p{
  text-indent: 2em;
    line-height: 2em;
    margin-bottom: 15px;
    color: #999;
    margin: 20px 0 0;
}

/* 内容区样式 */
.posts_container .outline pre{
  border:0px;background:white;
  white-space: pre-wrap;
  word-wrap: break-word;
  
  text-indent: 2em;
  line-height: 2em;
  margin-bottom: 15px;
  color: #333;
  font-size: 17px;
  text-align: left;
}

a{
  margin: 10px;
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
</style>